﻿angular.module("umbraco.resources").factory("districtResource",
    function ($q, $http, umbRequestHelper) {
        return {
            getProvince: function () {
                return umbRequestHelper.resourcePromise(
                    $http.get("backoffice/UmbracoDistrict/BackendDistrict/GetProvince"),
                    "Failed to retrieve province data."
                );
            },
            getCity: function (province, level) {
                return umbRequestHelper.resourcePromise(
                    $http.get("backoffice/UmbracoDistrict/BackendDistrict/GetCity",
                        { params: { province: province, level: level } }),
                    "Failed to retrieve city data."
                );
            },

            getDistrict: function (city) {
                return umbRequestHelper.resourcePromise(
                    $http.get("backoffice/UmbracoDistrict/BackendDistrict/GetDistrict",
                        { params: { city: city } }),
                    "Failed to retrieve district data."
                );
            },

            getOne: function (code) {
                return umbRequestHelper.resourcePromise(
                    $http.get("backoffice/UmbracoDistrict/BackendDistrict/GetOne",
                        { params: { code: code } }),
                    "Failed to retrieve detail data."
                );
            }

        };

    });